'use strict';

/**
 * copyright (c) 2017-2023 厦门风领科技有限公司
 * https://www.fengling.cn/
 * 
 * 初始化平台基础组件
 * zengbinsi
 * 2020-08-24
 */


import path from 'path';
import pathUtil from '../libs/utils/path-utils';
import fileUtil from '../libs/utils/file-utils';
import { callSequence } from '../libs/utils/function-call-seq';
const srcPath = pathUtil.getPathInTemplateAssets(path.join('bundles', 'framework', 'platform', 'base'));
const dstPath = pathUtil.getPathInAssets(path.join('bundles', 'framework', 'platform', 'base'));




// 初始化目录
const initDir = (callback?: Function) => {
    pathUtil.mkdirsSyncInAssets(path.join('bundles', 'framework', 'platform', 'base'), callback);
};


export const initFilePlatformBase = (fileName: string, callback?: Function) => {
    console.log(`[tool-box]import ${fileName}.ts...`);
    return callSequence([initDir, async (cb?: Function) => {
        fileUtil.copy(path.join(srcPath, `${fileName}.tsz`), path.join(dstPath, `${fileName}.ts`));
        await pathUtil.refreshAsset(`db://assets/bundles/framework/platform/base/${fileName}.ts`);
        console.log(`[tool-box]import ${fileName}.ts successed!`);
        cb && cb();
    }, callback]);
};